<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/ftl/css/bootstrap.min.css">
    <script src="/ftl/js/jquery/jquery.min.js"></script>
    <script src="/ftl/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="/ftl/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <style>
        input.error {
            border: 1px solid #c9150b;
        }
    </style>
</head>
<body>
<div class="container">
    <form id="updateUserForm">
        <br/>
        <div class="form-group">
            <label for="username">用户名称：</label>
            <input type="text" class="form-control" id="username" name="username" value="${data.userName}"
                   placeholder="输入名称">
        </div>
        <div class="form-group">
            <label for="password">用户密码：</label>
            <input type="password" class="form-control" id="password" name="password" value="${data.passWord}"
                   placeholder="输入密码">
        </div>
        <div class="form-group">
            <label for="userage">用户年龄：</label>
            <input type="text" class="form-control" id="userage" name="userage" value="${data.age}" placeholder="输入年龄">
        </div>
        <div class="form-group">
            <button type="button" id="updateBtn" class="btn btn-success">确认修改</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
</body>
</html>
<script>
    var UpdateUser = function () {
        if (!check().form()) {
            return;
        }
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: '/user/updateUser.do',
            data: {
                id:${data.id},
                userName: $("#username").val(),
                passWord: $("#password").val(),
                age: $("#userage").val()
            },
            success: function () {
                $("#cancelBtn").click();
            }
        });
    }

    $("#updateBtn").click(function () {
        UpdateUser();
    })


    $("#cancelBtn").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.getUserPageList();
        parent.layer.close(index);
    });


    function check() {
        return $("#updateUserForm").validate({
            rules: {
                username: {
                    required: true
                },
                userage: {
                    required: true
                }
            },
            message: {
                username: {
                    required: ""
                },
                userage: {
                    required: ""
                }

            }
        });
    }

</script>